package com.example.xiaomi.Model.Dao;

import com.example.xiaomi.Model.entity.shoppingcartEntity;
import com.example.xiaomi.Model.utils.BaseDB;
import com.example.xiaomi.Model.utils.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class shoppingcartDao extends BaseDB {
    public Integer doDelete(int uid,int cid){
        String sql ="delete from is_details where 1 <=> 1 and did="+uid+" and cid <=> "+cid;
        return super.update(sql);
    }
    public List<shoppingcartEntity> specify(int id){
        String sql = "SELECT uid,cid,gname,dmail,gprice,damount,totalcost,ping FROM `is_details`,`is_ueser`,`is_gods`,`is_pictre` where 1 <=> 1 and is_details.did <=> is_ueser.uid and is_gods.gid <=> cid and pid <=> cid and uid <=>"+id;
        return super.query(sql,new shoppingcartDao.StuRowMapper());
    }
    class StuRowMapper implements RowMapper<shoppingcartEntity> {
        @Override
        public shoppingcartEntity rowmap(ResultSet rs) throws SQLException {
            return new shoppingcartEntity(rs.getInt("uid"),
                                          rs.getInt("cid"),
                                          rs.getString("gname"),
                                          rs.getString("dmail"),
                                          rs.getBigDecimal("gprice"),
                                          rs.getInt("damount"),
                                          rs.getBigDecimal("totalcost"),
                                          rs.getString("ping"));
        }
    }
}
